﻿using EquipSecs300;
using SecsEquip;
using SecsEquip300;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EquipSecs300
{
    public class GEM_Constant:SecsEquipEx
    {
        public string m_pViewName;
        public GEM_Constant(CSecsEquip300 m_pSecs, SecsEquipHelper secsEquipHelper)
        {
            this.m_pSecs = m_pSecs;
            this.SecsEquipHelper = secsEquipHelper;
        }
        public override void UpdateData()
        {
            m_pSecs.m_pConstantValueCallback += OnConstantValueHandler;
            m_pSecs.m_pConstantChangeCallback += OnConstantChangeHandle;
        }

        // 添加常量
        public void AddDataToSECS(long nECID, string pName, string description, string varClass,
            string ValueType, string pUnits, string pMinValue,string pMaxValue,string pDefValue)
        {
            m_pSecs.ConstantsAdd(nECID, pName, description, ValueType, pUnits, pMinValue,pMaxValue,pDefValue);
        }

        // 设置对应ID需要的回调
        public void SetValueCallBack(int nVID)
        {
            m_pSecs.ConstantsSetMethod(nVID);
        }

        /// <summary>
        /// Host查询常量值回调（事情先调用过ConstantsSetMethod方法）
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        [Description("委托方式获取常量")]
        public string OnConstantValueHandler(object sender, ConstantValueEventArgs e)
        {
            string pValue = "";

            // 返回VID的值
            switch (e.nECID)
            {
                case 22003: pValue = "12"; break;
            }

            return pValue;
        }
        /// <summary>
        /// Host改变常量值回调
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        [Description("常量值发生改变：常量ID和数值")]
        public void OnConstantChangeHandle(object sender, ConstantChangeEventArgs e)
        {
            int ecid = e.nECID;
            string value = e.pValue.ToString();
        }
    }
}
